package org.jash.demo2205.utils

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData

val bus by lazy { SingleLiveData<Pair<String,*>>() }


fun observerAll(owner: LifecycleOwner, obj:Any = owner) {
    val methods = obj.javaClass.declaredMethods
    for (method in methods) {
        val event = method.getAnnotation(Event::class.java)
        if (event != null) {
            bus.observe(owner) {
                if (it.first == event.value) {
                    method.invoke(obj, it.second)
                }
            }
        }
    }
}